package com.seashop.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author moredln
 * @desc 路由配置
 * @date 2020-08-05 14:25
 */
@Configuration
public class RouteConfig {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("SeaShop-Api", r -> r.path("/api/**")
                        .filters(f -> f.rewritePath("/api/(?<path>.*)", "/$\\{path}"))
                        .uri("lb://api"))
                .route("SeaShop-Manage", r -> r.path("/manage/**")
                        .filters(f -> f.rewritePath("/manage/(?<path>.*)", "/$\\{path}"))
                        .uri("lb://manage"))
                .route("SeaShop-User", r -> r.path("/user/**")
                        .filters(f -> f.rewritePath("/user/(?<path>.*)", "/$\\{path}"))
                        .uri("lb://user"))
                .route("SeaShop-Product", r -> r.path("/product/**")
                        .filters(f -> f.rewritePath("/product/(?<path>.*)", "/$\\{path}"))
                        .uri("lb://product"))
                .route("SeaShop-Order", r -> r.path("/order/**")
                        .filters(f -> f.rewritePath("/order/(?<path>.*)", "/$\\{path}"))
                        .uri("lb://order"))
                .route("SeaShop-Third", r -> r.path("/third/**")
                        .filters(f -> f.rewritePath("/third/(?<path>.*)", "/$\\{path}"))
                        .uri("lb://third"))
                .build();
    }
}
